﻿using System;
using System.Collections.Generic;
using PgBirdie.Core.Model.Database.Structure;

namespace PgBirdie.Core.Model.Database.Data
{
    public class PgDataRow : IUid
    {
        public PgTable Table { get; private set; }        
        public string Uid { get; private set; }

        /// <summary>
        /// Dictionary key = column name.
        /// </summary>
        public IDictionary<string, PgDataColumn> DataColumns { get; private set; }

        public PgDataRow(PgTable table, IDictionary<string, PgDataColumn> dataColumns)
        {
            var values = new List<string>();
            foreach (var columnName in table.PrimaryKey.ColumnNames)
                values.Add(dataColumns[columnName].Value);

            Table = table;
            Uid = String.Format("{0}|{1}|{2}", table.Schema.Name, table.Name,
                                String.Join("|", values.ToArray()));
            DataColumns = dataColumns;
        }
    }
}